package com.deeper.customview.ui.c4.demo.c04d05;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.SweepGradient;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class SweepGradientView extends View {


    private Paint paint;


    public SweepGradientView(Context context) {
        super(context);
    }


    public SweepGradientView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.FILL);
    }


    public SweepGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.save();
        Rect rect = new Rect(100, 100, 500, 500);
        SweepGradient sg = new SweepGradient(
                300, 300, Color.GREEN, Color.YELLOW
        );
        paint.setShader(sg);
        canvas.drawRect(rect, paint);
        canvas.restore();

        canvas.save();
        canvas.translate(0, 600);
        SweepGradient sg2 = new SweepGradient(
                300, 300, new int[]{Color.GREEN, Color.YELLOW, Color.RED, Color.GREEN}, null
        );
        paint.setShader(sg2);
        canvas.drawCircle(300, 300, 200, paint);
        canvas.restore();
    }
}
